<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
    <title>注册页面</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/polyfill.js"></script><%--使ie兼容es6语法--%>
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">  <%--兼容ie浏览器--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/frozenui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/base-2.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery/jquerymin.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/register.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/dist/css/layui.css">
    <script src="${pageContext.request.contextPath}/static/layui/dist/layui.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/axios-min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/live_meeting.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/register.css">
    <style>
        .layui-form-select .layui-edge{
            right: 45px;
        }
        .aui-footer-fixed{
            display: none;
        }
    </style>
</head>
<body>
<div class="main" style="height: 800px">
<div class="c-title">
    <span class="glyphicon glyphicon-chevron-left" style="position: absolute;left: 15px;top: 15px;font-size: 18px" onclick="self.location=document.referrer;"></span>
    <div style="position: absolute;left: 100px;top: 85px;font-size: 20px;color: #ffffff">欢迎来到群爱智慧诊疗</div>
    <div class="logo">
        <img src="${pageContext.request.contextPath}/resource/images/login-qunai.png" width="55" height="55"
             style="margin-top: 2px;border-radius:50px" alt="">
    </div>
    <p class="name"></p>
</div>

<div class="c-login">
    <h1 style="display: inline-block">注册</h1><a href="/bokehall/user/login"
                                                style="display: block;font-size: 12px;position:absolute;top: 15px;right: 30px">已有账号?直接登录</a>
    <form class="loginForm layui-form" autoComplete="off">
        <%--<img src="${pageContext.request.contextPath}/resource/images/login-user.png" width="18" height="21" alt="" style="position: absolute;left: 56px;top: 51px">  &lt;%&ndash;优化&ndash;%&gt;--%>
        <input id="username" type="text" class="userLogo" placeholder="请设置登录名(数字或字母)" lay-verify="required|userName"/>
        <i class="layui-icon layui-icon-close-fill"
           style="position: absolute;top:54px;right:40px;color: #ababab;font-size: 18px" onclick="fontClear('f-1')"></i>
        <input id="phone" type="text" class="userPhone" placeholder="请输入手机号码" lay-verify="phone"/>
        <i class="layui-icon layui-icon-close-fill"
           style="position: absolute;top: 109px;right:40px;color: #ababab;font-size: 18px"
           onclick="fontClear('f-2')"></i>
        <input id="code" type="text" class="userLogo" placeholder="邀请码(选填)" style="margin-bottom: 0"/>
        <br>
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left: 2px">
                <select id=types name="interest" lay-filter="aihao">
                    <option value="" selected="">用户类型</option>
                    <option value="doctor">医生</option>
                    <option value="patient">患者</option>
                    <option value="assistant">互联网医助专员</option>
                </select>
            </div>
        </div>
        <input style="display:none">
        <input id="password" type="password" placeholder="请输入密码" lay-verify="required" autocomplete="new-password"/>
        <input id="password-2" type="password" placeholder="请确认密码" lay-verify="required" autocomplete="new-password"/>
        <input type="button" value="注册" id="regBtn"/>
        <div id="xieyi">
            <input id="agreement" type="checkbox" name="like1[write]" lay-skin="primary" title="" value="ok"
                   style="padding: 0">
            <span>我已阅读并同意群爱预约诊疗系统</span><span style="color: #f9711d" onclick="Agreement(1)">用户协议</span><span>和</span><span
                style="color: #f9711d" onclick="Agreement(2)">隐私条款</span>
        </div>
    </form>
</div>
</div>
<footer class="aui-footer aui-footer-fixed">

    <a href="/boke/index.jsp" class="aui-tabBar-item " style="text-decoration:none;">
        <span class="aui-tabBar-item-icon"><i class="icon icon-loan"></i></span>
        <span class="aui-tabBar-item-text">首页</span></a>

    <a href="/bokehall/hall/allHall" class="aui-tabBar-item aui-tabBar-item-active">
        <span class="aui-tabBar-item-icon"><i class="icon icon-credit"></i></span>
        <span class="aui-tabBar-item-text">会诊</span></a>

    <a href="/boke/msg/chatfriend.jsp" class="aui-tabBar-item ">
        <span class="aui-tabBar-item-icon"><i class="icon icon-ions"></i></span>
        <span class="aui-tabBar-item-text">消息</span></a>

    <a href="/boke/me.jsp" class="aui-tabBar-item "><span
            class="aui-tabBar-item-icon"><i class="icon icon-mine"></i></span>
        <span
                class="aui-tabBar-item-text">我的
        </span></a>
</footer>
<script type="text/javascript">
    var Regx = /^[A-Za-z0-9]*$/;
    var i = 0;
    $(document).ready(function () {
        i = 0;
        //调用获取地址栏参数的方法                  //备注:扫描二维码或分享链接注册的话用这个请求/user/submitRegister?code=(邀请人的推广码),这个页面代码不用动,已经改好了
        var myurl = GetQueryString("code"); //(如果是通过扫描其他用户二维码进入注册页面后地址栏会带上code=(邀请人的推广码),页面拿到并自动填入
        //自动填充邀请码,并且设置用户不能修改
        if (myurl != null && myurl.toString().length > 1) {
            $("#code").val(myurl)
            $("#code").attr("readOnly",true);
        }
        $("#password").val('');
    });
    //验证方法
    $('#regBtn').click(function () {

        if (!checkInputFunction($('#regBtn'))) {
            return false;
        }
        if(!Regx.test($("#username").val())){
            layer.msg('用户名只能是数字或字母', function () {
            });
            return false;
        }
        if ($('#types option:selected').val() == '' || $('#types option:selected').val() == null) {
            //失败提示
            layer.msg('用户类型必选', function () {
            });
            return false;
        }
        if ($("#password").val() != $("#password-2").val()) {
            layer.msg('两次密码输入不一致哦', {icon: 5});
            return false;
        }
        //复选框是否点击判断方法
        let j = (i % 2 == 0) ? true : false;
        if (j) {
            layer.tips('请勾选同意条款哦', '#xieyi', {
                tips: [1, '#78BA32'],
                time: 1500

            });
            return false
        }
        let form5 = new FormData();
        form5.append("loginName", $("#username").val());
        form5.append("phone", $("#phone").val());
        form5.append("inviteCode", $("#code").val());
        form5.append("userType", $('#types option:selected').val());
        form5.append("password", $("#password").val());
        axios({
            method: 'post',                             //备注:扫描二维码或分享链接注册的话用这个请求/user/submitRegister?code=(邀请人的推广码),这个页面代码不用动,已经改好了
            url: '${pageContext.request.contextPath}/user/submitRegister',
            data: form5
        })
            .then(function (r) {
                if (r.data.msg === "当前用户名已被注册") {
                    layer.msg('用户名已被注册', {icon: 5});
                    return false;
                }
                if (r.data.msg === "当前手机号已注册") {
                    layer.msg('手机号已被注册', {icon: 5});
                    return false;
                }
                if (r.data.code === 1) {
                    layer.msg('注册成功,即将跳转登录页', {icon: 1});
                    //弹出提醒框提示用户注册成功,1.5秒后跳转登录页
                    setTimeout(function () {
                        location.href = "/bokehall/user/login";
                    }, 1000)
                } else if (r.data.code === 0) {
                    alert("注册失败,请重试")
                }

            });
    });

    function fontClear(i) {
        if (i== "f-1") {
            $(".userLogo").val(null)
        } else {
            $(".userPhone").val(null)
        }
    }

    //点击复选框逻辑
    $("#xieyi").on("click", ".layui-unselect", function () {
        i++;
    });

    //获取地址栏后面的参数
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    function Agreement(index) {
        window.location.href="${pageContext.request.contextPath}/user/terms/"+index;
    }
</script>

</body>
</html>
